package com.example.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/**
 * @author swain
 * @description:
 * @date 2020/12/3
 */
public class FileUtils {

    /**
     * @Description 创建文件
     * @Param filePath
     * @return java.io.File
     * @Author swain
     * @Date  2020/12/3
     */
    public static File createFile(String filePath) throws Exception {
        File file = new File(filePath);
        if (!file.exists()) {
            File dir = new File(file.getParent());
            dir.mkdirs();
            file.createNewFile();
        }
        return file;
    }

    public static void main(String[] args) {
        readTxt();
    }

    public static void readTxt(){
        Map<String, String> map = new HashMap<String, String>();
        String path = "C:\\Users\\lks007\\Desktop\\a.txt";
        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append("select count(1) from FROM [LksForSetting].[basic].[Country] c WHERE c.CName in (");
        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(path)), "UTF-8"))){
            String lineTxt = null;
            // 逐行读取
            while ((lineTxt = br.readLine()) != null) {
                // 每行数据以逗号分隔
                String[] names = lineTxt.split(",");
                // 处理数据, 可以转成entity, 在这儿转换成map
                map.put(names[0], names[1]);
//                stringBuilder.append("'"+names[1]+"',");

                stringBuilder.append("UPDATE [LksForSetting].[basic].[Country] SET countryCode = '"+names[0]+"' WHERE cname = '"+names[1]+"';");

            }
//            stringBuilder.append(");");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
